<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Banner;
use app\common\model\City;
use app\common\model\Notice;
use app\common\model\user\Jz;

/**
 * 就诊人接口
 */
class UserJz extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];

    /**
     * 添加/编辑就诊人
     *
     */
    public function addEdit()
    {
        $params = request()->param();
        extract($params);
        if (!isset($name) || !$name) {
            $this->error('请填写姓名');
        }
        if (!isset($mobile) || !$mobile) {
            $this->error('请填写手机号');
        }
        $params['user_id'] = $this->auth->id;
        $jz = new Jz;
        if (isset($id) && $id) {
            $jz=$jz->get($id);
            unset($params['id']);
        }
        $res = $jz->allowField(true)->save($params);
        if ($res) {
            $this->success('成功');
        }
        $this->error('失败');
    }

    /**
     * 就诊人列表
     *
     */
    public function list()
    {
        $jz = new Jz;
        $list = $jz->where('user_id', $this->auth->id)->paginate(10);
        $this->success('成功', $list);
    }
    public function del()
    {
        $params = request()->param();
        extract($params);
        $jz = new Jz;
        $jz->get($id)->delete();
        $this->success('删除成功');
    }
    /**
     * 获取默认就诊信息
     *
     */
    public function defaultJz()
    {
        $jz = new Jz;
        $info = $jz->get(['user_id' => $this->auth->id, 'is_default' => 1]);
        $this->success('成功', $info);
    }
}
